//
//  AddressBooke.m
//  Homework05
//
//  Created by Rain on 16/5/27.
//  Copyright © 2016年 Rain. All rights reserved.
//

#import "AddressBooke.h"
#import "Contact.h"

@implementation AddressBooke

- (instancetype)init {
    
    self = [super init];
    
    if (self) {
        
        self.dicOfContacts = [NSMutableDictionary dictionary];
        
    }
    return self;
}

- (void)addContact:(Contact *)contact {
    
    // 获取与分组名相对应的数组
    NSMutableArray *arrayOfContacts = [_dicOfContacts objectForKey:contact.group];
    
    // 如果数组为空, 说明字典内不存在此分区.
    if (arrayOfContacts == nil) {
        
        // 创建数组.
        arrayOfContacts = [NSMutableArray arrayWithObject:contact];
        
        // 将数组添加到字典内.
        [_dicOfContacts setObject:arrayOfContacts forKey:contact.group];
        
    } else {
        [arrayOfContacts addObject:contact];
    }
    
}






@end
